package visualization.renderers.utils
{
	import mx.core.UIComponent;
	
	public class DrawingUtils
	{
		public function DrawingUtils()
		{
		}
		
		/*
		 * The following function is based off of code found at
		 * http://leebrimelow.googlecode.com/svn/trunk/as3/com/theflashblog/drawing/Wedge.as
		 */
		public static function drawArc(t:UIComponent, sx:Number, sy:Number, radius:Number, arc:Number, angle:Number=0, color:uint = 0):void 
		{
			var segAngle:Number;
			var angleMid:Number;
			var numOfSegs:Number;
			var ax:Number;
			var ay:Number;
			var bx:Number;
			var by:Number;
			var cx:Number;
			var cy:Number;
			
			// Move the pen
			t.graphics.moveTo(sx, sy);
			
			// No need to draw more than 360
			if (Math.abs(arc) > Math.PI * 2) 
			{
				arc = Math.PI * 2;
			}
			
			numOfSegs = Math.ceil(Math.abs(arc) / (Math.PI/4));
			segAngle = arc / numOfSegs;
			
			// Calculate the start point
			ax = sx + Math.cos(angle) * radius;
			ay = sy + Math.sin(angle) * radius;
			
			// Draw the first line
			t.graphics.lineTo(ax, ay);

			for (var i:int=0; i<numOfSegs; i++) 
			{
				angle += segAngle;
				angleMid = angle - (segAngle / 2);
				bx = sx + Math.cos(angle) * radius;
				by = sy + Math.sin(angle) * radius;
				cx = sx + Math.cos(angleMid) * (radius / Math.cos(segAngle / 2));
				cy = sy + Math.sin(angleMid) * (radius / Math.cos(segAngle / 2));
				t.graphics.curveTo(cx, cy, bx, by);
			}
			
			// Close the wedge
			t.graphics.lineTo(sx, sy);
		}


	}
}